package com.wyh.mapper;

import com.wyh.entity.Houses;
import com.wyh.entity.Houses_Id_Address;
import com.wyh.utils.sqlUtils.house.addHouseSqlDynamic;
import com.wyh.utils.sqlUtils.house.updateHouseSqlDynamic;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface HouseMapper {
    //通过address查找房屋返回house_id
    @Select("SELECT house_id FROM house WHERE address = #{address} ")
    Houses findHouseIdByAddress(@Param("address") String address);
    //查找房屋
    @Select("SELECT house_id FROM house WHERE house_id = #{house_id} ")
    Houses findExist(@Param("house_id") Long house_id);

    // 查找房屋信息
    // todo 通过房屋id查找房屋信息
    @Select("SELECT house.*, user.username,user.uid " +
            "FROM user " +
            "LEFT JOIN user_house ON user.uid = user_house.user_id " +
            "LEFT JOIN house ON user_house.house_id = house.house_id " +
            "WHERE user.uid = #{uid}")
    List<Houses> findHousesByUserId(@Param("uid") Integer uid);

    @Select("select house_id from house where address=#{address}")
    int findHouse_idByAddress(String address);

    @Select("select house.house_id, house.address from house")
    List<Houses_Id_Address> getAllHouseIDAndAddress();

    //获取房屋信息
    @Select("SELECT house.*, user.username " +
            "FROM house " +
            "LEFT JOIN user_house ON house.house_id = user_house.house_id " +
            "LEFT JOIN user ON user_house.user_id = user.uid")
    List<Houses> findAllHouse();

    //增加房屋信息
    @InsertProvider(type = addHouseSqlDynamic.class , method = "addDynamic")
    void addHouse(Houses houses);

    //修改房屋信息
    @UpdateProvider(type = updateHouseSqlDynamic.class , method = "updateDynamic")
    void updateHouse(Houses houses);

    //删除房屋信息
    @Delete("DELETE FROM house WHERE house_id = #{house_id}")
    void deleteHouse(@Param("house_id") Long house_id);


}




